package com.train.lookup;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("ALL")
public class TwoLookup {
    public static void main(String[] args){
        int[] arr={1,8,10,89,1000,1000,1000,1234};
        List list=twoLookup(arr,0,arr.length-1,1000);
        System.out.println(list);
    }
    public static ArrayList twoLookup(int[] arr,int left,int right,int val){
        if(left>right)
            return null;
        int middle=(left+right)/2;
        if(arr[middle]<val){
            return twoLookup(arr,middle+1,right,val);
        }else if(arr[middle]>val)
        {
            return twoLookup(arr,left,middle-1,val);
        }else{
            ArrayList list=new ArrayList();
            int temp=middle;
            while(temp>=0&&arr[temp]==val){
                list.add(temp--);
            }
            temp=middle+1;
            while(temp<=arr.length-1&&arr[temp]==val){
                list.add(temp++);
            }
            return list;
        }
    }
}